package socket.tcp.demo1;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author 周宇
 * @create 2020-05-26 17:14
 */
public class ServerDemo {
    public static void main(String[] args) throws IOException {
        //2
        ServerSocket ss = new ServerSocket(8888);
        Socket accept = ss.accept();
        InputStream is = accept.getInputStream();
        int b;
        while ((b = is.read()) != -1) {
            System.out.println((char) b);
        }
        System.out.println("看看我执行了吗？");
        // OutputStream os = accept.getOutputStream();
        // os.write("你谁啊？".getBytes());
        //改写成使用字符流
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw.write("你谁阿？");
        bw.newLine();
        bw.flush();

        bw.close();
        is.close();
        accept.close();
        ss.close();
    }
}
